跳到主要内容

CreateChart

Creates a chart with the parameters specified.

Syntax

expression.CreateChart(chartType, series, seriesNames, catNames, width, height, styleIndex, numFormats);

expression - A variable that represents a Api class.

Parameters

NameRequired/OptionalData typeDefaultDescription
chartTypeOptionalChartType"bar"The chart type used for the chart display.
seriesRequiredArrayThe array of the data used to build the chart from.
seriesNamesRequiredArrayThe array of the names (the source table column names) used for the data which the chart will be build from.
catNamesRequiredArrayThe array of the names (the source table row names) used for the data which the chart will be build from.
widthRequiredEMUThe chart width in English measure units.
heightRequiredEMUThe chart height in English measure units.
styleIndexRequirednumberThe chart color style index (can be 1 - 48, as described in OOXML specification).
numFormatsRequiredNumFormat[]String[]

Returns

ApiChart

Example

This example shows how to create a chart and paste it into the document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let chart = Api.CreateChart("bar3D", [
[200, 240, 280],
[250, 260, 280]
], ["Projected Revenue", "Estimated Costs"], [2014, 2015, 2016], 4051300, 2347595, 24);
paragraph.AddDrawing(chart);
let solidFill = Api.CreateSolidFill(Api.CreateRGBColor(51, 51, 51));
chart.SetSeriesFill(solidFill, 0, false);
solidFill = Api.CreateSolidFill(Api.CreateRGBColor(255, 111, 61));
chart.SetSeriesFill(solidFill, 1, false);